﻿<%@ Page Title="" Language="C#" MasterPageFile="~/TsSite.Master" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="TireService.Web.View.WarehouseOperatorView.Index" %>

<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxRatingControl" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxLoadingPanel" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxCallback" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxCallbackPanel" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dx" %>


<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <!-- Javascript variables used in control -->
    <script language="javascript" type="text/javascript">

        function OnSelectedContainerChanged(s) {
            if (ddlContainer.GetValue() != null) {
                ddlScheduleDate.PerformCallback(ddlContainer.GetValue());
                gvStockTask.PerformCallback(ddlContainer.GetValue());
                gvTireSetWaiting.PerformCallback(ddlContainer.GetValue());
            }
        }

        function OnSelectedScheduleDateChanged(s) {
            if (ddlContainer.GetValue() != null) {

                var datestring = ddlScheduleDate.GetText().split("-");
                var daystring = datestring[0];
                var monthstring = datestring[1];
                var yearstring = datestring[2].substring(0, 4);
                //var scheduleDate = new Date(ddlScheduleDate.GetText());
                //var stringDate = scheduleDate.getDate() + "-" + (1 + scheduleDate.getMonth()) + "-" + scheduleDate.getFullYear();
                var stringDate = daystring + "-" + monthstring + "-" + yearstring;

                window.open('PackingList.aspx?ContainerId=' + ddlContainer.GetValue() + "&ScheduleDate=" + stringDate, '_self', 'Pakkelister');
            } else {
                alert('Vælg et lager først');
            }
        }

        // Function that return error in case callback to server failed
        function CallBackError(s, e) {
            LoadingPanel.Hide();

            alert('Fejl opstod: ' + e.message);
        }

        // Function for searching on tireset based on car registration number
        function SearchOnRegistrationNumber(s, e) {
//            // Validate values
//            txtRegistrationNumber.Validate();

//            var isFormValid = ASPxClientEdit.ValidateGroup("SearchOnRegistrationNumber");
//            if (isFormValid) {
//                // Clear search result
//                lblSearchResult.SetText('');

//                // Prepare input for search (0: SearchType, 1: SearchValue)
//                var input = 4 + '|' + txtRegistrationNumber.GetText();

//                // Callback server to get customers based on search
//                gvCustomerSearch.PerformCallback(input);

//                // Show loadingpanel
//                LoadingPanel.Show();
//            }
        }

        function SearchOnCargoRoomNumber(s, e) { 
        
        }
    </script>


    <dx:ASPxLoadingPanel ID="LoadingPanel" Text="Vent venligst..." ClientInstanceName="LoadingPanel" runat="server" Modal="True">
    </dx:ASPxLoadingPanel>

    <table cellpadding="0" cellspacing="2" border="0">
        <tr>
            <td>
                <img id="imgWarehouseOperatorView" alt="" src="~/Images/Medium/cubes_yellow.png" runat="server" style="width: 32px; height: 32px" />
            </td>
            <td valign="middle">
                <h1><asp:Label ID="lblWarehouseOperationView" runat="server" Text="Lager"></asp:Label></h1>
            </td>
        </tr>
    </table>

    <table width="100%">
        <tr>
            <td valign="top" style="width:310px">
                <h3>Pakkelister</h3>
                <table width="100%">
                    <tr>
                        <td valign="top">
                            <dx:ASPxComboBox ID="ddlContainer" ClientInstanceName="ddlContainer" runat="server" Width="300px" Height="40px">
                                <ListBoxStyle Font-Size="Large" />
                                <ItemStyle Font-Size="Large" />
                                <ButtonStyle Font-Size="Large">
                                </ButtonStyle>
                                <ClientSideEvents SelectedIndexChanged="function(s, e) { OnSelectedContainerChanged(s); }" />
                            </dx:ASPxComboBox>
                        </td>
                    </tr>
                    <tr>
                        <td valign="top">
                            <dx:ASPxComboBox ID="ddlScheduleDate" ClientInstanceName="ddlScheduleDate" runat="server" Width="300px" Height="40px" OnCallback="ddlScheduleDate_Callback">
                                <ListBoxStyle Font-Size="Large" />
                                <ItemStyle Font-Size="Large" />
                                <ButtonStyle Font-Size="Large">
                                </ButtonStyle>
                                <ClientSideEvents SelectedIndexChanged="function(s, e) { OnSelectedScheduleDateChanged(s); }" />
                            </dx:ASPxComboBox>
                        </td>
                    </tr>
                </table>
                <hr />
                <table width="100%">
                    <tr>
                        <td colspan="2">
                            <h3>Find hjulsæt</h3>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <dx:ASPxTextBox ID="txtRegistrationNumber" NullText="Regnr" ClientInstanceName="txtRegistrationNumber" runat="server" Width="250px" Height="40px" Font-Size="Large">
                                <ValidationSettings CausesValidation="true" ValidationGroup="SearchOnRegistrationNumber" RequiredField-IsRequired="true" RequiredField-ErrorText="Indtast regnr" SetFocusOnError="true" ErrorDisplayMode="None">
                                    <RequiredField IsRequired="True" ErrorText="Indtast regnr"></RequiredField>
                                </ValidationSettings>
                                <ClientSideEvents KeyDown="function(s, e) {if(ASPxClientUtils.GetKeyCode(e.htmlEvent) ===  ASPxKey.Enter) SearchOnRegistrationNumber();}" />
                            </dx:ASPxTextBox>
                        </td>
                        <td>
                            <dx:ASPxButton ID="btnRegistrationNumberSearch" ClientInstanceName="btnRegistrationNumberSearch" runat="server" Text="Søg" AutoPostBack="False" Width="50px" Height="40px" UseSubmitBehavior="False" Font-Size="Large">
                                <ClientSideEvents Click="function(s, e) { SearchOnRegistrationNumber(); }" />
                            </dx:ASPxButton>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <dx:ASPxTextBox ID="txtCargoRoomNumber" NullText="Lagerplads" ClientInstanceName="txtCargoRoomNumber" runat="server" Width="250px" Height="40px" Font-Size="Large">
                                <ValidationSettings CausesValidation="true" ValidationGroup="SearchOnRegistrationNumber" RequiredField-IsRequired="true" RequiredField-ErrorText="Indtast lagerplads" SetFocusOnError="true" ErrorDisplayMode="None">
                                    <RequiredField IsRequired="True" ErrorText="Indtast lagerplads"></RequiredField>
                                </ValidationSettings>
                                <ClientSideEvents KeyDown="function(s, e) {if(ASPxClientUtils.GetKeyCode(e.htmlEvent) ===  ASPxKey.Enter) SearchOnCargoRoomNumber();}" />
                            </dx:ASPxTextBox>
                        </td>
                        <td>
                            <dx:ASPxButton ID="btnCargoRoomNumberSearch" ClientInstanceName="btnCargoRoomNumberSearch" runat="server" Text="Søg" AutoPostBack="False" Width="50px" Height="40px" UseSubmitBehavior="False" Font-Size="Large">
                                <ClientSideEvents Click="function(s, e) { SearchOnCargoRoomNumber(); }" />
                            </dx:ASPxButton>
                        </td>
                    </tr>
                </table>
            </td>
            <td valign="top">
                <h3>Backlog</h3>
                <dx:ASPxGridView ID="gvStockTask" runat="server" Caption="Lager opgaver" Width="100%"
                    KeyFieldName="TaskId" AutoGenerateColumns="False" ClientInstanceName="gvStockTask"
                    OnCustomCallback="gvStockTask_CustomCallback">
                    <SettingsBehavior ProcessFocusedRowChangedOnServer="false" AllowFocusedRow="true" />
                    <SettingsPager AlwaysShowPager="False" PageSize="25" Position="Bottom">
                        <Summary 
                            AllPagesText="Sider: {0} - {1} ({2} åbne opgaver)" 
                            Text="Side {0} af {1} ({2} åbne opgaver)" />
                    </SettingsPager>
                    <Settings ShowGroupPanel="True" />
                    <Columns>
                        <dx:GridViewDataColumn FieldName="TaskId" VisibleIndex="1" Caption="Opgavenr">
                        </dx:GridViewDataColumn>
                        <dx:GridViewDataColumn FieldName="TaskTypeId" VisibleIndex="1" Visible="false" Caption="TaskTypeId">
                        </dx:GridViewDataColumn>
                        <dx:GridViewDataColumn FieldName="TaskTypeDescription" VisibleIndex="1" Caption="Type">
                        </dx:GridViewDataColumn>
                        <dx:GridViewDataColumn FieldName="TaskTypeStatusId" VisibleIndex="1" Visible="false" Caption="TaskTypeStatusId">
                        </dx:GridViewDataColumn>
                        <dx:GridViewDataColumn FieldName="TaskTypeStatusDescription" VisibleIndex="1" Caption="Status">
                        </dx:GridViewDataColumn>
                        <dx:GridViewDataHyperLinkColumn FieldName="CustomerId" VisibleIndex="1" Caption="Kundenr">
                            <PropertiesHyperLinkEdit NavigateUrlFormatString="~/View/CustomerView/EditCustomerData.aspx?CustomerId={0}" TextField="CustomerId">
                            </PropertiesHyperLinkEdit>
                        </dx:GridViewDataHyperLinkColumn>
                        <dx:GridViewDataColumn FieldName="RegistrationNumber" VisibleIndex="1" Caption="Regnr.">
                        </dx:GridViewDataColumn>
                        <dx:GridViewDataColumn FieldName="ContainerId" VisibleIndex="1" Visible="false" Caption="ContainerId">
                        </dx:GridViewDataColumn>
                        <dx:GridViewDataColumn FieldName="ContainerNumber" VisibleIndex="1" Caption="Lager">
                        </dx:GridViewDataColumn>
                        <dx:GridViewDataColumn FieldName="Createdate" VisibleIndex="1" Caption="Oprettet">
                        </dx:GridViewDataColumn>
                        <dx:GridViewDataColumn FieldName="CompletionDate" VisibleIndex="1" Caption="Afsluttet">
                        </dx:GridViewDataColumn>
                    </Columns>
                    <Templates>
                        <DetailRow>
                            Opgavedetaljer
                            <br />
                            <dx:ASPxGridView ID="gvTaskDetail" ClientInstanceName="gvTaskDetail" runat="server" KeyFieldName="TaskDetailId"
                                Width="100%" OnBeforePerformDataSelect="gvTaskDetail_DataSelect">
                                <Columns>
                                    <dx:GridViewDataColumn FieldName="TaskDetailId" Caption="Id" VisibleIndex="1" />
                                    <dx:GridViewDataColumn FieldName="TaskDetailTypeId" Caption="Type" Visible="false" VisibleIndex="2" />
                                    <dx:GridViewDataColumn FieldName="Description" Caption="Beskrivelse" VisibleIndex="2" />
                                    <dx:GridViewDataColumn FieldName="EstimatedTime" Caption="Estimeret tid" VisibleIndex="2" />
                                    <dx:GridViewDataColumn FieldName="Amount" Caption="Antal" VisibleIndex="3" />
                                    <dx:GridViewDataColumn FieldName="NoteToEmployee" Caption="Note" VisibleIndex="4" />
                                    <dx:GridViewDataColumn FieldName="Completed" Caption="Afsluttet" VisibleIndex="5" />
                                    <dx:GridViewDataColumn FieldName="Cancelled" Caption="Annulleret" VisibleIndex="6" />
                                </Columns>
                            </dx:ASPxGridView>
                        </DetailRow>
                    </Templates>
                    <SettingsDetail ShowDetailRow="true" AllowOnlyOneMasterRowExpanded="true" />
                    <SettingsLoadingPanel Mode="ShowOnStatusBar" />
                    <Styles>
                        <Header ImageSpacing="5px" SortingImageSpacing="5px" />
                    </Styles>
                </dx:ASPxGridView>
                <hr />
                <dx:ASPxGridView ID="gvTireSetWaiting" runat="server" Caption="Afventende hjulsæt" Width="100%"
                    KeyFieldName="TireSetId" AutoGenerateColumns="False" ClientInstanceName="gvTireSetWaiting"
                    OnCustomCallback="gvTireSetWaiting_CustomCallback">
                    <SettingsBehavior ProcessFocusedRowChangedOnServer="false" AllowFocusedRow="true" />
                    <SettingsPager AlwaysShowPager="False" PageSize="25" Position="Bottom">
                        <Summary 
                            AllPagesText="Sider: {0} - {1} ({2} ventende hjulsæt)" 
                            Text="Side {0} af {1} ({2} ventende hjulsæt)" />
                    </SettingsPager>
                    <Settings ShowGroupPanel="True" />
                    <Columns>
                        <dx:GridViewDataColumn FieldName="ContainerNumber" VisibleIndex="1" Caption="Lager">
                        </dx:GridViewDataColumn>
                        <dx:GridViewDataColumn FieldName="CargoRoomNumber" VisibleIndex="2" Caption="Lagerplads">
                        </dx:GridViewDataColumn>
                        <dx:GridViewDataColumn FieldName="RegistrationNumber" VisibleIndex="2" Caption="Reg.nr">
                        </dx:GridViewDataColumn>
                        <dx:GridViewDataColumn FieldName="TireTypeId" Visible="false" VisibleIndex="5" Caption="TireTypeId">
                        </dx:GridViewDataColumn>
                        <dx:GridViewDataTextColumn FieldName="TireTypeDescription" VisibleIndex="5" Caption="Dæktype">
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataColumn FieldName="TireBrandId" Visible="false" VisibleIndex="5" Caption="TireBrandId">
                        </dx:GridViewDataColumn>
                        <dx:GridViewDataTextColumn FieldName="TireBrandDescription" VisibleIndex="5" Caption="Mærke">
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataTextColumn FieldName="Width" VisibleIndex="6" Caption="Bredde">
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataColumn FieldName="Height" VisibleIndex="7" Caption="Højde">
                        </dx:GridViewDataColumn>
                        <dx:GridViewDataColumn FieldName="Size" VisibleIndex="8" Caption="Fælgstr.">
                        </dx:GridViewDataColumn>
                    </Columns>
                    <SettingsLoadingPanel Mode="ShowOnStatusBar" />
                    <Styles>
                        <Header ImageSpacing="5px" SortingImageSpacing="5px" />
                    </Styles>
                </dx:ASPxGridView>
                <hr />
                <dx:ASPxGridView ID="gvStockMovingTask" runat="server" Caption="Venter lagerflyt" Width="100%"
                    KeyFieldName="TireSetId" AutoGenerateColumns="False" ClientInstanceName="gvStockMovingTask"
                    OnCustomCallback="gvStockMovingTask_CustomCallback">
                    <SettingsBehavior ProcessFocusedRowChangedOnServer="false" AllowFocusedRow="true" />
                    <SettingsPager AlwaysShowPager="False" PageSize="25" Position="Bottom">
                        <Summary 
                            AllPagesText="Sider: {0} - {1} ({2} venter lagerflyt)" 
                            Text="Side {0} af {1} ({2} venter lagerflyt)" />
                    </SettingsPager>
                    <Settings ShowGroupPanel="True" />
                    <Columns>
                        <%--<dx:GridViewDataTextColumn FieldName="CustomerId" VisibleIndex="0" Caption="Kundenr" />
                        <dx:GridViewDataTextColumn FieldName="ServiceCarScheduleDetailId" Visible="false" VisibleIndex="0" />
                        <dx:GridViewDataTextColumn FieldName="ScheduleDate" Visible="false" VisibleIndex="0" />
                        <dx:GridViewDataTextColumn FieldName="ServiceCarId" Visible="false" VisibleIndex="0" />
                        <dx:GridViewDataTextColumn FieldName="ToLongitude" Visible="false" VisibleIndex="0" />
                        <dx:GridViewDataTextColumn FieldName="ToLatitude" Visible="false" VisibleIndex="0" />
                        <dx:GridViewDataTextColumn FieldName="CarId" Visible="false" VisibleIndex="0" />
                        <dx:GridViewDataTextColumn FieldName="ContainerId" Visible="false" VisibleIndex="0" />
                        <dx:GridViewDataTextColumn FieldName="ScheduleDetailTypeId" Visible="false" VisibleIndex="0" />
                        <dx:GridViewDataTextColumn FieldName="Note" Visible="false" VisibleIndex="0" />
                        <dx:GridViewDataTextColumn Caption="Navn" FieldName="Name" VisibleIndex="2" />
                        <dx:GridViewDataTextColumn Caption="Postnr" FieldName="ToZipCode" VisibleIndex="4" />
                        <dx:GridViewDataTextColumn Caption="By" FieldName="ToCity" VisibleIndex="5" />
                        <dx:GridViewDataTextColumn Caption="Reg.nr." FieldName="RegistrationNumber" VisibleIndex="7" />
                        <dx:GridViewDataTextColumn Caption="Bil" FieldName="CarBrandDescription" VisibleIndex="7" />
                        <dx:GridViewDataColumn>
                            <DataItemTemplate>
                                <dx:ASPxButton ID="btnInsert" runat="server" ClientInstanceName="btnInsert" Text="Færdigmeld sag" ToolTip="Klik for at færdigmelde sag" AutoPostBack="false"
                                    ClientSideEvents-Click='<%# "function(s, e) { MarkServiceAsCompleted(" + Container.KeyValue + "); }" %>'>
                                </dx:ASPxButton>                                           
                            </DataItemTemplate>
                        </dx:GridViewDataColumn>--%>
                    </Columns>
                    <SettingsLoadingPanel Mode="ShowOnStatusBar" />
                    <Styles>
                        <Header ImageSpacing="5px" SortingImageSpacing="5px" />
                    </Styles>
                </dx:ASPxGridView>
            </td>
        </tr>
        
    </table>

</asp:Content>
